import TimerBaseCommand from './timerBaseCommand';

class QueryTimerCommand extends TimerBaseCommand {
  static CMD = 0x09;  // 查询定时事件列表命令

  /**
   * 创建查询定时列表命令
   */
  static createCommand() {
    return this.packFrame(this.CMD);
  }

  /**
   * 解析查询定时列表响应
   * @param {Uint8Array} frame - 响应数据帧
   */
  static parseResponse(frame) {
    const parsed = this.parseBaseFrame(frame);
    if (!parsed || parsed.cmd !== this.CMD) return null;

    const timerCount = Math.floor(parsed.data.length / 11);  // 每个定时器11字节
    const timers = [];

    for (let i = 0; i < timerCount; i++) {
      const timerData = parsed.data.slice(i * 11, (i + 1) * 11);
      const timer = this.parseTimeData(timerData);
      timers.push(timer);
    }

    return { timers };
  }
}

export default QueryTimerCommand; 